package com.zhihuanbao.business.sys.controller;


import com.zhihuanbao.common.core.controller.BaseController;
import com.zhihuanbao.common.core.domain.AjaxResult;
import com.zhihuanbao.common.utils.file.MinIOUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;

@Api("用户信息管理")
@RestController
@RequestMapping("/test/file")
public class MinIOController extends BaseController {

    @Autowired
    private MinIOUtil minIOUtil;

    @ApiOperation("上传文件")

    @PostMapping("/upload")
    public AjaxResult upload(@RequestParam("file") MultipartFile file, String fileName)
    {
        fileName=file.getOriginalFilename();
        minIOUtil.upload(file,fileName);
        return AjaxResult.success("上传成功");
    }
    @ApiOperation("获取用户列表")
    @GetMapping("/download")
    public ResponseEntity<byte[]> downloadFile(@RequestParam("fileName")String fileName)
    {
        return minIOUtil.download(fileName);
    }

    @GetMapping("/getUrl")
    public AjaxResult getFileUrl(@RequestParam("fileName") String fileName){
        HashMap map=new HashMap();
        map.put("FileUrl",minIOUtil.getFileUrl(fileName));
        return AjaxResult.success(map);
    }

}
